import { getErrors } from './getErr'
import { getPath } from '../utils/getPath'
import {lazyReportCache} from '../report'

export function onVueError(config) {
  if(!config.vue) return
  if (!config.vue.Vue) return

  config.vue.Vue.config.errorHandler = function (errInfo, vm, info) {
    const stack = errInfo.stack
    const [err] = getErrors(stack)
    const path = getPath()
    
    const data = {
      errorType: 'vueError',
      filename: err.filename,
      functionName: err.functionName,
      lineno: err.lineno,
      colno: err.colno,
      message: errInfo.message,
      stack,
      path
    }

    lazyReportCache('error', data)
  }
}
